//
//  DangerViewController.m
//  Umoney
//
//  Created by zwz on 16/10/29.
//  Copyright © 2016年 zhangwz. All rights reserved.
//

#import "DangerViewController.h"

@interface DangerViewController ()
{
    NSString *UID;
    NSString *PID;
    NSArray *res;
    NSString *GetMoney;
}

@end

@implementation DangerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(instancetype)initWithCode:(NSString *)pid andUser:(NSString *)uid getMoney:(NSString *)getmoney
{
    UID = uid;
    PID = pid;
    GetMoney = getmoney;
    return self;
}

- (IBAction)DoOkAction:(id)sender {
    NSString *urlString = [NSString stringWithFormat:@"http://23.106.134.160/umoney/invest.php?uid=%@&pid=%@&getmoney=%@",UID,PID,GetMoney];
    
    NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
    config.timeoutIntervalForRequest = 30.0f;
    config.timeoutIntervalForResource = 60.0f;
    NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
    NSURLSessionTask *task = [session dataTaskWithURL:[NSURL URLWithString:urlString] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        res = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
        
    }];
    [task resume];
    [self alter];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

-(void)alter
{
    UIAlertController *altervc = [UIAlertController alertControllerWithTitle:@"提示" message:@"投资成功" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
        [self.navigationController popToRootViewControllerAnimated:YES];
    }];
    [altervc addAction:confirm];
    
    [self presentViewController:altervc animated:NO completion:nil];
    
}


@end
